import { getMaterial } from "@/api/order";
import { getTenctChang, addOrder, queryMaterial } from "@/api/tx";

import { getToken, setToken, removeToken } from "@/utils/auth";

import { resetRouter } from "@/router";
// 引入请求管理后台文件
import { accMul, accAdd } from "@/utils/acc";
const getDefaultState = () => {
  return {
    token: getToken(),
    name: "",
    avatar: "",
  };
};

const state = getDefaultState();

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState());
  },
  SET_TOKEN: (state, token) => {
    state.token = token;
  },
  SET_NAME: (state, name) => {
    state.name = name;
  },
  SET_AVATAR: (state, avatar) => {
    state.avatar = avatar;
  },
};

const actions = {
  addOrder({ commit }, userInfo) {
    // userInfo = {
    //   dbilldate: "2023-10-04 18:00:00",
    //   custphone: "13226443534",
    //   ctrantypeid: "30-01",
    //   corigcurrencyid: "人民币",
    //   bvo: [
    //     {
    //       castunitid: "个",
    //       cmaterialid: "243532",
    //       nqtorigtaxprice: 5,
    //       nnum: 20,
    //       dsenddate: "2023-10-04 21:55:00",
    //     },
    //   ],
    // };
    debugger;
    return addOrder(userInfo);
    // return creteOrder(userInfo);
  },

  // user login
  getMaterial({ commit }, userInfo) {
    console.log(userInfo);
    // const { username, password } = userInfo;
    //传后台json对象userName
    // login({ userName: username.trim(), password: password })
    return queryMaterial(userInfo);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
